package servlet;

import java.io.IOException;

import java.text.DateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.BookService;
import service.ScrapService;

public class ScrapAdd extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	// TODO Auto-generated method stub


	String sdetail=req.getParameter("sdetail");
	sdetail=new String(sdetail.getBytes("ISO-8859-1"),"utf-8");
	String bid=req.getParameter("bid");
	String uuser=req.getParameter("uuser");
	String outtime=req.getParameter("time");
	String num=req.getParameter("snum");
	int snum=1;
	if(outtime==null){
	Date time=new Date();
	outtime=DateFormat.getDateInstance().format(time);
	}
	if(num!=""){
		snum=Integer.parseInt(num);
	}
	int state=0;
	ScrapService sps=new ScrapService();
	sps.insert(bid, uuser, snum, outtime, sdetail,state);
	req.getRequestDispatcher("/jsp/addScrap.jsp").forward(req, resp);
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
	doGet(req, resp);
	}
}
